#include"HttpServer.hpp"


using namespace LogModule;

void Login(HttpRequest &req,HttpResponse &resp)
{
	// 根据req动态创建resp
	LOG(LogLevel::DEBUG) << "进入登陆模块:" << req.Path() << "," << req.Args();

	// 根据request得到response
	std::string req_aargs = req.Args();
	// 1.解析参数格式，得到要的参数

	// 2.访问数据库,,验证对应的用户是否为合法用户

	// 3.登陆成功

	// 显示登陆成功页面
	std::string body = req.GetContent("wwwroot/success.html");
	resp.SetCode(200); 
	resp.SetHeader("Content-Length",std::to_string(body.size()));
	resp.SetHeader("Content-type","text/html");
	resp.SetHeader("Content-Cookie","username=zhangsan&passwd=123456");
	resp.SetBody(body);

	// 回到首页
	// resp.SetCode(302);
	// resp.SetHeader("Location","/");
}
int main()
{
	auto httpserver = std::make_unique<HttpServer>(8080);

	// 要让服务器具有登陆功
	httpserver->Register("/login",Login); 

	httpserver->Start();

	return 0;
}